package com.yjc.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yjc.springcloud.service.PaymentHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create 2022-07-24 15:06
 */
@RestController
public class OrderController {

    @Autowired
    PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String orderInfo_OK(@PathVariable("id") Integer id) {
        return paymentHystrixService.paymentInfo_OK(id);
    }
    @HystrixCommand(fallbackMethod = "orderInfo_TimeOutHandler",
            commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String orderInfo_TimeOut(@PathVariable("id") Integer id) {
        return paymentHystrixService.paymentInfo_TimeOut(id);
    }
    public String orderInfo_TimeOutHandler(@PathVariable("id") Integer id) {
        return "消费者80,线程池：" + Thread.currentThread().getName() + " ，id: " + id + " ,系统运行超时或出错，请稍后再试.../(ㄒoㄒ)/失败~~~~~";
    }

}
